package scala.test_feature.test_match

import scala.test_class.test_case_class.{Email, Notification, SMS}
import scala.util.Random

/**
 * @author 黄海峰 2021/4/19 11:21
 * */
object DeanTest {
  def main(args: Array[String]): Unit = {
    transformNum(2)

    val email = Email("huanghaifeng15@jd.com")
    println(showNotification(email))
    val sms = SMS("hello,dean!")
    println(showNotification(sms))
  }

  def transformNum(x: Int): Unit = {
    x match {
      case 0 => println("zero")
      case 1 => println("one")
      case _ => println("other")
    }
  }

  def showNotification(notification: Notification): String = {
    notification match {
      case Email(sender) => s"You got an email from $sender;"
      case SMS(message) => s"You got an SMS Message: $message"
    }
  }
}

/**
 * An object is a class that has exactly one instance.
 * It is created lazily when it is referenced, like a lazy val.
 *
 * As a top-level value, an object is a singleton.
 *
 * As a member of an enclosing class or as a local value, it behaves exactly like a lazy val.
 *
 * When using a companion object from Java code,
 * the members will be defined in a companion class with a static modifier.
 * This is called static forwarding. It occurs even if you haven’t defined a companion class yourself.
 *
 *
 */
